home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
rng.exe
/
SAMPLE.C
< prev
Wrap
C/C++ Source or Header
|
1991-12-19
|
1KB
|
46 lines
/* sample.c - Illustrates how to use the random number generator and tests
** the Marsaglia operator to make sure it's working properly
*/
#include <stdio.h>
#ifdef __STDC__
#include <time.h>
#endif
#include "ran.h"
main() {
double dummy; /* dummy variable used to store results */
double x[3]; /* used to store results to report */
#ifdef __STDC__
double tm; /* used to store time */
#endif
unsigned long seed; /* seed used in random number generator */
int i; /* index variable */
setup(&seed); /* r.n.g. must be initialized before use */
#ifdef __STDC__
tm = (double)clock();
#endif
for (i = 0; i < 20000; i++) {
dummy = ran();
}
#ifdef __STDC__
tm = (double)clock() - tm;
#endif
printf("The random numbers should be:\n");
printf("\t%.1f %.1f %.1f\n", 6533892.0, 14220222.0, 7275067.0);
printf("\t%.1f %.1f %.1f\n\n", 6172232.0, 8354498.0, 10633180.0);
printf("The results are:\n");
for (i = 0; i < 3; i++) {
x[i] = 4096.0*4096.0*ran();
}
printf("\t%.1f %.1f %.1f\n", x[0], x[1], x[2]);
for (i = 0; i < 3; i++) {
x[i] = 4096.0*4096.0*ran();
}
printf("\t%.1f %.1f %.1f\n", x[0], x[1], x[2]);
#ifdef __STDC__
printf("\n%f microseconds per call\n", ((tm/CLOCKS_PER_SEC)/20000)*1000000);
#endif
}